//-----------------------------------------------------------------------
// <copyright file="FeedbackOverviewPresenter.cs" company="Simnova LLC">
//     Copyright (c) Simnova LLC. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Simnova.Collaborate.Presenter
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    public class FeedbackOverviewPresenter
    {
        private readonly View.IFeedbackOverview feedbackOverviewView;
        private readonly int userId;

        public FeedbackOverviewPresenter(View.IFeedbackOverview feedbackOverviewView, int userId)
        {
            this.userId = userId;
            this.feedbackOverviewView = feedbackOverviewView;
            this.LoadCompanies();
            this.LoadProducts();
        }

        public void LoadProducts()
        {
            AppServer.CollaborateServiceClient collaborateClient = new AppServer.CollaborateServiceClient();
            this.feedbackOverviewView.Products = collaborateClient.GetProductsByCompany(this.feedbackOverviewView.SelectedCompanyId);
            collaborateClient.Close();
            this.LoadFeedbackLists();
        }

        public void LoadFeedbackLists()
        {
            this.LoadTopRatedFeedback();
            this.LoadWatchListFeedback();
            this.LoadNewestFeedback();
        }

        private void LoadTopRatedFeedback()
        {
            AppServer.CollaborateServiceClient collaborateClient = new AppServer.CollaborateServiceClient();
            this.feedbackOverviewView.TopRatedFeedback = collaborateClient.GetTopRatedProductFeedback(this.feedbackOverviewView.SelectedProductId, 10);
            collaborateClient.Close();
        }

        private void LoadWatchListFeedback()
        {
            AppServer.CollaborateServiceClient collaborateClient = new AppServer.CollaborateServiceClient();
            this.feedbackOverviewView.WatchListFeedback = collaborateClient.GetWatchListProductFeedback(this.feedbackOverviewView.SelectedProductId, this.userId, 10);
            collaborateClient.Close();
        }

        private void LoadNewestFeedback()
        {
            AppServer.CollaborateServiceClient collaborateClient = new AppServer.CollaborateServiceClient();
            this.feedbackOverviewView.NewestFeedback = collaborateClient.GetNewestProductFeedback(this.feedbackOverviewView.SelectedProductId, 10);
            collaborateClient.Close();
        }

        private void LoadCompanies()
        {
            AppServer.CollaborateServiceClient collaborateClient = new AppServer.CollaborateServiceClient();
            this.feedbackOverviewView.Companies = collaborateClient.GetCompanies();
            collaborateClient.Close();
            this.LoadProducts();
        }
    }
}
